package y_2025.m05.d23;

public class GreetingThread2 implements Runnable {
    private final String greeting;

    public GreetingThread2(String greeting) {
        this.greeting = greeting;
    }

    @Override
    public void run() {
        for (int i = 0; i < greeting.length(); i++) {
            System.out.println(Thread.currentThread().getName() + ": " + greeting.charAt(i));
            try {
                Thread.sleep(1000); // 间隔1秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        // 创建两个线程
        Thread thread1 = new Thread(new GreetingThread2("welcome!"), "线程A");
        Thread thread2 = new Thread(new GreetingThread2("welcome!"), "线程B");

        thread1.start();
        thread2.start();
    }
}